import request from '@/utils/request'

// 获取公文列表
export function getDocumentPage(params) {
  return request({
    url: '/documents/page',
    method: 'get',
    params
  })
}

// 获取待我审批的公文列表
export function getPendingApprovalPage(params) {
  return request({
    url: '/documents/pending',
    method: 'get',
    params
  })
}

// 获取我已审批的公文列表
export function getApprovedPage(params) {
  return request({
    url: '/documents/approved',
    method: 'get',
    params
  })
}

// 获取我创建的公文列表
export function getMyDocumentPage(params) {
  return request({
    url: '/documents/my',
    method: 'get',
    params
  })
}

// 获取抄送给我的公文列表
export function getCcToMePage(params) {
  return request({
    url: '/documents/cc',
    method: 'get',
    params
  })
}

// 获取公文详情
export function getDocumentDetail(id) {
  return request({
    url: `/documents/${id}`,
    method: 'get'
  })
}

// 创建公文
export function createDocument(data) {
  return request({
    url: '/documents',
    method: 'post',
    data
  })
}

// 更新公文
export function updateDocument(data) {
  return request({
    url: '/documents',
    method: 'put',
    data
  })
}

// 删除公文
export function deleteDocument(id) {
  return request({
    url: `/documents/${id}`,
    method: 'delete'
  })
}

// 提交公文审批
export function submitDocument(id) {
  return request({
    url: `/documents/${id}/submit`,
    method: 'post'
  })
}

// 归档公文
export function archiveDocument(id) {
  return request({
    url: `/documents/${id}/archive`,
    method: 'post'
  })
}

// 上传附件
export function uploadAttachment(data) {
  return request({
    url: '/documents/attachment',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 删除附件
export function deleteAttachment(id) {
  return request({
    url: `/documents/attachment/${id}`,
    method: 'delete'
  })
}

// 获取公文统计数据
export function getDocumentStatistics(userId) {
  return request({
    url: '/documents/statistics',
    method: 'get',
    params: { userId }
  })
}